package com.mall.manager.singletopicday.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.util.WebUtils;

import com.mall.manager.singletopicday.service.SingleTopicDayService;
import com.mall.untils.Page;
import com.mall.untils.StringUtil;

/**
 * 单题按天统计
 * 
 * @author liugb
 * @date 2016 7 7
 */
@Controller
@RequestMapping("/manager")
public class SingleTopicDayController {
	Logger logger = LoggerFactory.getLogger(SingleTopicDayController.class);
	@Resource
	SingleTopicDayService singleTopicDayService;

	/**
	 * 单题按天统计列表
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/manager_singleTopicDay_list")
	public String manager_singleTopicDay_list(HttpServletRequest request,
			HttpServletResponse response, ModelMap modelMap) {
		Page page = singleTopicDayService.manager_singleTopicDay_list(request);
		Map<String, Object> paraMap = WebUtils.getParametersStartingWith(
				request, "");
		String topic_name = MapUtils.getString(paraMap, "topic_name");
		if (!StringUtils.isEmpty(topic_name)) {
			modelMap.addAttribute("name",
					StringUtil.getByteToString(topic_name));
		}
		if (null != page) {
			modelMap.addAttribute("manager_singleTopicDay_list",
					(List<Map<String, Object>>) page.getResult());
			int totalpagecount = page.getTotalPageCount();
			modelMap.addAttribute("totalpagecount", totalpagecount);
			int currentpageno = page.getCurrentPageNo();
			modelMap.addAttribute("currentpageno", currentpageno);
			int previouspage = page.getCurrentPageNo() <= 1 ? 1 : page
					.getCurrentPageNo() - 1;
			modelMap.addAttribute("previouspage", previouspage);
			int nextpage = page.getCurrentPageNo() >= page.getTotalPageCount() ? page
					.getTotalPageCount() : page.getCurrentPageNo() + 1;
			modelMap.addAttribute("nextpage", nextpage);
			List<Integer> showNumList = page.getShowNumList();
			modelMap.addAttribute("pagenumlist", showNumList);
		}
		return "singletopicday/danti_list1";
	}

}
